The following is a step by step guide of how to connect to GitHub. This is just for practice!
Go to github.com and login using your credentials!
To make a new repository, click the green button.
Name and create your repository, Lab2.
Once you are done, click the green Create repository button.
Now that your repsitory is created, we want to clone this onto our computer.
Copy this link!
Once you have the link copied, open Terminal for Mac or cmd for Windows. (For the purpose of this lab, terminal will be used because that is what we have on our computers!) We wish to go to the directory that we want our repository to be in. To change your directory, use cd to move. If you ever get lost, use type in pwd to see which directory you are in.
When you are in your desired directory, type in the following code in the terminal and replace the url with the one you copied in the previous step.
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
If you have done this correctly, you should get an output similar to this on your terminal.
With our repository on our local computer, we want to make a change and push it back to GitHub!
To do this, we will add a line to our README file! Enter the following line to your terminal.
echo "I am writing on this markdown file using the command prompt." >> README.md
If we want to check if this actually worked, we can enter this code on the terminal.
git status
It worked! Now we want to save what we did by commiting it to GitHub. Follow the code line by line!
git add -A
git commit -m "My first commit through the command prompt"
git push
All this is doing is adding the change that we made, commiting it so that we are sure we want to make the change, and then pushing it to our repository that we have on GitHub. Once all of this is done, you will see that your repository will be updated on GitHub.
Go to your repository on GitHub and make sure that the change has been made.
Our commit message is there, which means that it has gone through! Congratulations! :-)
The following is a step by step guide of how to connect to RStudio to Git and GitHub. This is just for practice!
Next we are going to use RStudio to connect to GitHub
First, we want to open RStudio and create a new Project.
…and then select “Git”.
When you reach this screen, paste the URL of your new GitHub repository into the box labeled “Repository URL”.
Make sure that your project directory name and location make sense. If you can’t find your projects, then all of your hard work is meaningless.
A good name might be “Lab2”.
Make sure the box labeled “Open in a new session” is checked.
Finaly, click “Create Project”.
Let’s do some work on this new project!
From RStudio, create a new RMarkdown file. Title it something sensible.
Lets practice making a basic scatterplot. For this example, we’re going to invent some data (we go through loading in data later on). Right now though, feel free to use whatever values you want.
a <- c(2,4,3,8,5)
b <- c(3,4,7,6,9)
Next, lets make a basic scatterplot without changing any of the default settings. Do this with the following command:
plot(a,b)
Pretty cool!
That graph is kind of ugly though. Let’s add some improvments:
First, we want to give our scatterplot a title. We need to change our code just a bit. This time, instead of just typing plot(a,b), try:
plot(a,b, main = "My Scatterplot")
Lets add some labels, too.
plot(a,b,main = "My Scatterplot", xlab = "Pringles Eatten", ylab = "Happiness")
Maybe there’s a relationship here? Let’s test it out by adding a regression line to our scatterplot.
plot(a,b,main = "My Scatterplot", xlab = "Pringles Eatten", ylab = "Happiness")
abline(lm(b~a))
There’s definitely something going on here. But unfortunatly, we’re out of Pringles, and we want to take a break and go to Ham to get some more.
It’s probably a good idea to save our work first though.
Let’s commit these edits to our repository.
On the next screen, you should notice that it will say something like “your branch is ahead of master by 1 commit.” This is because the changes we’ve made are only saved on your local machine. We need to add them to our cloud based github repository.
To do this, click the “Push” button.
Great job! To check that everything worked properly, go back to GitHub in your browser and refresh the page. You should be able to see your changes.
Now that you have gone though all of this…we want you to put your skills to the test.
DataVis2018 and add your Lab1 from last week to it. Here are the general steps again:Hint: You can add files to your repository folder to add them as changes!
Next, go to this link and download the Cereal dataset. You can also get access to the data through the Lock5withR package. Create a new folder in your DataVis2018 repository and name it Lab2 with the dataset inside.
Create a new R Markdown file inside Lab2 and load the dataset as the variable, cereal. In a sentence or two, explain what this dataset holds and show the head() of the data like so:
| Name | Company | Serving | Calories |
|---|---|---|---|
| AppleJacks | K | 1 | 117 |
| Boo Berry | G | 1 | 118 |
| Cap’n Crunch | Q | 0.75 | 144 |
| Cinnamon Toast Crunch | G | 0.75 | 169 |
| Cocoa Blasts | Q | 1 | 130 |
| Cocoa Puffs | G | 1 | 117 |
| Fat | Sodium | Carbs | Fiber | Sugars | Protein |
|---|---|---|---|---|---|
| 0.6 | 143 | 27 | 0.5 | 15 | 1 |
| 0.8 | 211 | 27 | 0.1 | 14 | 1 |
| 2.1 | 269 | 31 | 1.1 | 16 | 1.3 |
| 4.4 | 408 | 32 | 1.7 | 13.3 | 2.7 |
| 1.2 | 135 | 29 | 0.8 | 16 | 1 |
| 1 | 171 | 26 | 0.8 | 14 | 1 |
Sugars as the explanatory variable and Calories as the response. Here is an example of how one would look like. You can try to group the plot by the Company. If not, thats totally fine as well.Can you provide a summary() for the two variables(Sugars and Calories) that we are interested in?
Intermediate: Find the linear model for the relationship between Sugars and Calories for each group and put it on the graph. Explain the trend. What kind of relationship seems to be there?
Intermediate: Can we make any conclusions about this relationship? Why or why not? (Is the correlation significant, are the data normally distributed, etc.)
When you are done, add, commit, and push your markdown file to the repository! Make sure to go to your GitHub to see if everything is on there!
Want to do some more? Go here for our more advanced supplementary lab!
Good luck!